package com.mxprojects.gui
{
	import com.mxprojects.constructors.ButtonLarge;
	import com.mxprojects.io.Config;
	import com.mxprojects.language.Language;
	import com.mxprojects.language.Word;
	
	import flash.events.MouseEvent;

	public class ConfirmDialog extends DefaultDialog
	{
		private static var yesFunction:Function;
		private static var noFunction:Function;
		
		public function ConfirmDialog(){}
		
		public static function confirm(message:String, title:String, functionOnYes:Function, functionOnNo:Function = null, showStageOnClose:Boolean = true):void {
			//create the window
			if(popup != null){
				closeDialog();
			}
			
			//set the shared vars
			showStage = showStageOnClose;
			yesFunction = functionOnYes;
			noFunction = functionOnNo;
			
			//show the popup
			createPopup(title);
			popup.createTextBlock(message, noFunction);
			
			//create the buttons
			var yesButton:ButtonLarge = popup.createActionButton(Language.main(Word.YES), handleYes);
			var noButton:ButtonLarge = popup.createActionButton(Language.main(Word.NO), handleNo);
			
			//center the buttons
			yesButton.x = Math.round(popup.width/2 - (yesButton.width + Config.TEXT_PADDING*2 + noButton.width)/2);
			noButton.x = Math.round(yesButton.x + yesButton.width + Config.TEXT_PADDING*2);
		}
		
		private static function handleYes(event:MouseEvent):void {
			//close the dialog and then handle the yes function
			closeFunction = yesFunction;
			closeDialog();
		}
		
		private static function handleNo(event:MouseEvent):void {
			//close the dialog and then handle the no function
			closeFunction = noFunction;
			closeDialog();
		}
	}
}